<template>
  <div style="height: 1000px">
    <re-upload
      :action="`/rdms-admin/common/file/upload`"
      ref="uploadRef"
      :beforeUpload="beforeUpload"
      @file-uploaded-error="errorMessage"
      @file-uploaded-success="successMessage"
      :beforeRemove="beforeRemove"
      multiple="true"
      :limit="2"
    >
      <template #default>
        <el-button>选择文件</el-button>
      </template>
    </re-upload>
  </div>
</template>

<script lang="ts" setup>
import { ref } from "vue";
import ReUpload from "/@/components/ReUpload/index.vue";
import { ElMessageBox, ElMessage } from "element-plus";

const uploadRef = ref(null);

const errorMessage = error => {
  console.log(error, "error");
};
const successMessage = data => {
  console.log(data, "success-data");
  if (data.code === 0) {
    ElMessage.success({
      message: `${data.message}`,
      type: "success"
    });
  }
};
const beforeUpload = () => {
  // if (file.type === "image/jpeg") {
  //   return true;
  // } else {
  //   return false;
  // }
  return true;
};
const beforeRemove = async () => {
  // const res = ElMessageBox.confirm(
  //   "此操作将永久删除该文件, 是否继续?",
  //   "提示",
  //   {
  //     confirmButtonText: "确定",
  //     cancelButtonText: "取消",
  //     type: "warning",
  //     center: true
  //   }
  // )
  //   .then(() => {
  //     ElMessage({
  //       type: "success",
  //       message: "删除成功!"
  //     });
  //     return true;
  //   })
  //   .catch(() => {
  //     return false;
  //   });
  const result = await ElMessageBox.confirm(
    "此操作将永久删除该文件, 是否继续?",
    "提示",
    {
      confirmButtonText: "确定",
      cancelButtonText: "取消",
      type: "warning",
      center: true
    }
  );
  if (result) {
    return true;
  } else {
    return false;
  }
};
</script>

<style lang="scss" scoped></style>
